#coding :utf-8

import platform
import os
from selenium import webdriver

class BrowserOption(object):
    def __init__(self):
        print "BrowerOption"
        self.driver_path = os.getcwd()+'\\browers\\'
        self.driver_list = os.listdir(self.driver_path)
        print self.driver_list
        self.localSys = platform.architecture()
        self.driver_map = {'chrome':webdriver.Chrome, 
                           'edge':webdriver.Edge, 
                           'phantomjs':webdriver.PhantomJS}

    def selectBrower(self):
        browserOb = None
        if('windows' in self.localSys[1].lower()):
            for driver_name in self.driver_list:
                driver_total_path = self.driver_path + driver_name
                #os.environ["webdriver.chrome.driver"] = chromedriver 
                browser_name = driver_name.split('.')[0].lower()
                try:
                    if(browser_name == "chrome"):
                        service_log_path = 'chromedriver.log'
                        service_args = ['--verbose', '--no-sandbox']
                        browserOb = apply(self.driver_map[browser_name])
                    else:
                        browserOb = apply(self.driver_map[browser_name],(driver_total_path,))
                    print "quinn:",browserOb
                    if(browserOb):
                        return browserOb
                    else:
                        raise Exception("no suitable browser driver")
                except Exception as e:
                    print str(e)
                    print('PC Have no {0}'.format(browser_name))
                    pass